﻿@{
    Layout = "_LayoutAdmin";
    ViewData["Title"] = "Home Page";
}

<div class="box">
    <div class="box-header with-border">
        <h3 class="box-title">文件编辑<span class="small">仅支持文本内容编辑</span></h3>
        <!-- /.box-tools -->
    </div>
    <!-- /.box-header -->
    <div class="box-body">
        <div class="row">
            <div class="col-md-2">
                <ul id="tree" class="ztree"></ul>
            </div>
            <div class="col-md-9">
                <iframe id="myFrame" style="width:100%;height:700px;"></iframe>
                @*<div id="container" style="width:100%;min-height:600px;border:1px solid grey"></div>*@
            </div>
        </div>
    </div>
    <!-- /.box-body -->
    <div class="box-footer">
        The footer of the box
    </div>
    <!-- box-footer -->
</div>
<!-- /.box -->

@section Styles{
    <link href="~/lib/zTree/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" />
    <style>
        #myFrame {
            border: none;
            padding: 0;
        }
    </style>
}
@section Scripts{
    <script src="~/lib/zTree/js/jquery.ztree.all.js"></script>
    <script src="~/js/common.js"></script>
    <script>
        var zTreeObj;
        // zTree 的参数配置，深入使用请参考 API 文档（setting 配置详解）
        var setting = {
            async: {
                enable: true,
                url: "/admin/getnode",
                autoParam: ["fname"]
            },
            callback: {
                onClick: zTreeOnClick
            }
        };
        function zTreeOnClick(event, treeId, treeNode) {
            //treeNode.fname
            $("#myFrame")[0].src = "/admin/editor?path=" + treeNode.fname;
        };

        function ztreeOnAsyncSuccess(event, treeId, treeNode) {
            var url = "unitAction!xzqhTree.action?parentId=";
            if (treeNode == undefined) {
                url += "1";
            }
            else {
                url += treeNode.id;
            }
            $.ajax({
                type: "post",
                url: url,
                data: "",
                dataType: "json",
                async: true,
                success: function (jsonData) {
                    if (jsonData != null) {
                        var data = jsonData.unitList;
                        if (data != null && data.length != 0) {
                            if (treeNode == undefined) {
                                treeObj.addNodes(null, data, true);// 如果是根节点，那么就在null后面加载数据
                            }
                            else {
                                treeObj.addNodes(treeNode, data, true);//如果是加载子节点，那么就是父节点下面加载
                            }
                        }
                        treeObj.expandNode(treeNode, true, false, false);// 将新获取的子节点展开
                    }
                },
                error: function () {
                    alert("请求错误！");
                }
            });
        };

        $(document).ready(function () {
            zTreeObj = $.fn.zTree.init($("#tree"), setting);
        });
    </script>
}